package com.ehaoyao.web;

import com.ehaoyao.entity.Order;
import com.ehaoyao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <dl>
 * <dt>MongoApi</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2006</dd>
 * <dd>CreateDate: 2020/6/13</dd>
 * </dl>
 *
 * @author zhangyp
 */
@RestController
@RequestMapping("/mongo")
public class MongoApi {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/{id}/{price}")
    public String save(@PathVariable(value = "id") String id, @PathVariable(value = "price") BigDecimal price){
        for(int i = 1 ;i<=Integer.valueOf(id);i++){
            Order order = new Order();
            order.setId(i);
            order.setPrice(price.multiply(BigDecimal.valueOf(i)));
            orderService.save(order);
        }
        return  id+"提交成功";
    }

    @PostMapping("/{id}")
    public Object getById(@PathVariable(value = "id") Integer id){
        return  orderService.selectById(id);
    }

    @PutMapping("/{id}")
    public String update(@PathVariable(value = "id") Integer id,@RequestBody Order order){
        orderService.update(order);
        return  id+"删除成功";
    }


    @DeleteMapping("/{id}")
    public String getOrderPay(@PathVariable(value = "id") Integer id){
        orderService.delete(id);
        return  id+"删除成功";
    }

    @PostMapping("/all")
    public Object getOrderAll(){
        return  orderService.selectAll();
    }


    @PostMapping("/list")
    public Object getOrderList(@RequestBody Order order){
        return  orderService.selectByParam(order);
    }
}

